# !/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2021/10/19 11:01
# @Author  : zuodengbo
# @Email   : zuodb@amoydx.com
# @File    : models
# @Software: PyCharm
from tortoise.models import Model
from tortoise import fields
from utils.common import time_now


class Crontab(Model):
    """
    crontab model
    timer format "* * * * *"
    """
    STATUS = (
        (0, "停止"),
        (1, "正常")
    )
    id = fields.IntField(pk=True)
    task_name = fields.CharField(max_length=20, unique=True, description="定时任务函数名，如：tasks.tasks.time_job")
    timer = fields.CharField(max_length=20, default="*/1 * * * *", description="定时任务函数名")
    status = fields.IntField(choices=STATUS, default=1, description="任务状态，0-停止， 1-正常")
    create_time = fields.DatetimeField(auto_now_add=True, default=time_now(), description="创建时间")

    def __str__(self):
        return self.task_name

    class Meta:
        table = "tbl_crontab"
